package com.example.springbootgoods.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springbootgoods.entity.Commodity;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


@Mapper
public interface CommodityMapper extends BaseMapper<Commodity> {

    @Select("SELECT c.*,cn.className AS 'className.className',b.brandName AS 'brand.brandName',COUNT(assessId) AS 'count'  FROM commodity c \n" +
            "JOIN className cn \n" +
            "ON c.classId=cn.classId\n" +
            "JOIN brand b\n" +
            "ON b.brandId=c.brandId\n" +
            "left JOIN assess a\n" +
            "ON a.cid=c.cid\n"+
            " ${ew.customSqlSegment}")
   Page<Commodity> selectByPage(@Param("page") Page<Commodity> page, @Param("ew") QueryWrapper<Commodity> wrapper);


    @Select("SELECT c.*,cn.className AS 'className.className',b.brandName AS 'brand.brandName'  FROM commodity c \n" +
            "JOIN className cn \n" +
            "ON c.classId=cn.classId\n" +
            "JOIN brand b\n" +
            "ON b.brandId=c.brandId\n" +
            "WHERE c.cid=#{cid}")
    Commodity selectById(@Param("cid") int cid);
}
